package simulateOS.UI;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import simulateOS.MainApplication;
import simulateOS.entity.FAT;
import simulateOS.entity.Folder;
import simulateOS.management.process.ProcessManager;

import javax.annotation.Resource;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class FileAppUI {
//    private File imagePath = new File("src\\main\\resources\\image");/*图片路径*/
    private BorderPane mainPane = new BorderPane();/*主体界面*/
    private StackPane stackPane = new StackPane();/*文件树界面*/
    private BorderPane preViewPane = new BorderPane();/*预览界面*/
    private TextArea load = new TextArea();/*路径显示界面*/
    private FlowPane flowPane = new FlowPane(5, 5);
    private ScrollPane scrollPane = new ScrollPane(flowPane);
    private List<Object> arrayListFile = new ArrayList<>();
    private List<VBox> arrayListVbox = new ArrayList<>();
    private BorderPane roadBorderPane = new BorderPane();
    //建立储存TreeView用的HHox
    private HBox mainBox = new HBox();

    private ClassLoader classLoader = FileAppUI.class.getClassLoader();
    //返回前进按钮,以及置顶的图片数显示
    private Image imageLeft = new Image(classLoader.getResourceAsStream("image/left.png"));
    private Image imageRight = new Image(classLoader.getResourceAsStream("image/right.png"));
    private ImageView imageViewLeft = new ImageView(imageLeft);
    private ImageView imageViewRight = new ImageView(imageRight);
    private Label buttonLeft = new Label();
    private Label buttonRight = new Label();
    private HBox buttonLRT = new HBox();
    //当前所在文件夹
    private Folder recentFolder = null;
    private Folder oldFolder = null;
    //右键菜单
    private ContextMenu commonMenu = new ContextMenu();
    private ContextMenu exeMenu = new ContextMenu();
    private ContextMenu txtMenu = new ContextMenu();
    private ContextMenu folderMenu = new ContextMenu();
    private MenuItem[] menuItems = new MenuItem[18];

    private Scene scene = new Scene(mainPane,600,600);
    private Stage stage = new Stage();
    private FAT fat = FAT.getFAT();
    private Folder ROOT_FILE = fat.getC();
    private TreeView treeView = new TreeView();
    private static FileAppUI fileAppUI = null;
    private TreeItem<String> root = new TreeItem<>(ROOT_FILE.getPath().getPathName(),new ImageView(new Image(classLoader.getResourceAsStream("image/C.png"))));
    private TreeItem<String> clickNode = root;


    public static FileAppUI getFileAppUI(){
        if(fileAppUI == null){
            fileAppUI = new FileAppUI();
        }
        return fileAppUI;
    }

    private FileAppUI() {
        //建立TreeView
        initTreeView();
        treeView.setMinWidth(80);
        treeView.setMaxWidth(150);
        mainBox.getChildren().add(treeView);
        //开始进行文件目录树整体界面的布局
        stackPane.getChildren().add(mainBox);
        //设置返回前进图标,以及置顶的图片数量显示
        buttonLeft.setGraphic(imageViewLeft);
        buttonRight.setGraphic(imageViewRight);
        buttonLRT.getChildren().addAll(buttonLeft, buttonRight);
        //建立显示当前文件夹路径的文本区域
        load.setEditable(false);//不可手动修改或者在TextArea中添加文字
        load.setText("C:");
        load.setPrefHeight(1);
        load.setStyle("-fx-font: 14 arial;-fx-text-fill:pink");
        roadBorderPane.setLeft(buttonLRT);
        roadBorderPane.setCenter(load);
        //进行预览界面的布置
        //预览流板
        flowPane.setPadding(new Insets(10, 20, 20, 30));
        flowPane.setOrientation(Orientation.HORIZONTAL);
        flowPane.setHgap(20);
        flowPane.setVgap(30);
        flowPane.setStyle("-fx-background-color: white");
        flowPane.setPrefSize(500, 600);
        preViewPane.setTop(roadBorderPane);
        preViewPane.setCenter(scrollPane);
        //进行主界面的布置
        mainPane.setLeft(stackPane);
        mainPane.setCenter(preViewPane);
        stage.setScene(scene);
        stage.setTitle("我的电脑");
        stage.getIcons().add(new Image(classLoader.getResourceAsStream("image/MyComputer.png")));
        //初始化右键菜单
        initMenu();
        //加入初始化的十个可执行文件
        for(simulateOS.entity.File s : FAT.getFAT().getFileList()){
            /**
             * 调用进程调度
             */
           ProcessManager processManager = (ProcessManager) MainApplication.applicationContext.getBean("processManager");
           processManager.createProcess(s);
        }


        //在这里判断点击了哪一个文件夹
        treeView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
            clickNode = (TreeItem<String>) treeView.getSelectionModel().getSelectedItem();
            //获取文件夹绝对地址
            String path = "";
            if(clickNode!=null){
                path = clickNode.getValue();
            }

            while(clickNode!=null && clickNode.getParent()!=null){
                clickNode = clickNode.getParent();
                path = clickNode.getValue() + "\\" + path;
            }
            if (newValue == null) {
                return;
            }
            System.out.println(path);
            openFolder(path);
            load.setText(path);
        });

        //右监听
        buttonRight.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                if(recentFolder!=null){
                    if(oldFolder!=null){
                        if(recentFolder.hasChildren()){
                            openFolder(oldFolder.getPath().getPathName());
                        }
                    }

                }
            }
        });

        //左监听
        buttonLeft.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                if(recentFolder!=null){
                    if(recentFolder.hasParent()){
                        setOldFolder(recentFolder);
                        openFolder(recentFolder.getParent().getPath().getPathName());
                    }
                }
            }
        });
    }


    private void initTreeView(){
        treeView.setRoot(root);
        treeView.setEditable(true);
        root.setExpanded(true);
        initNode(ROOT_FILE,root);
    }

    private void initNode(Folder folder,TreeItem<String> rootNode){
        TreeItem<String> treeItem = new TreeItem<>();
        if(folder.hasChildren()){
            for(int i = 0;i < folder.getChildren().size();i++){
                if(folder.getChildren().get((i)) instanceof Folder){
                    Folder temp = (Folder) folder.getChildren().get(i);
                    treeItem = new TreeItem<>(temp.getFolderName(),new ImageView(new Image(classLoader.getResourceAsStream("image/Folder.png"))));
                    rootNode.getChildren().add(treeItem);
                    initNode((Folder) folder.getChildren().get(i),treeItem);
                }
            }
        }
    }

    public void openFolder(String path){
        cleanPreView();
        load.setText(path);
        Folder folder = fat.getFolder(path);
        setRecentFolder(folder);
        if(folder.hasChildren()){
            int i,length = folder.getChildren().size();
            for(i = 0;i < length;i++){
                if(folder.getChildren().get(i) instanceof Folder){
                    Folder fold = (Folder) folder.getChildren().get(i);
                    VBox vBox = new VBox();
                    Label labelName = new Label(fold.getFolderName());
                    Image image = new Image(classLoader.getResourceAsStream("image/FolderP.png"),60, 60, true, true);
                    if(fold.hasChildren()){
                        image = new Image(classLoader.getResourceAsStream("image/FolderPHC.png"), 60, 60, true, true);
                    }
                    ImageView imageView = new ImageView(image);
                    //限定宽长、像素大小
                    labelName.setWrapText(true);
                    labelName.setPrefWidth(60);
                    labelName.setStyle("-fx-font: 8 arial;");
                    imageView.setPreserveRatio(true);
                    //自动换行
                    labelName.setAlignment(Pos.BASELINE_CENTER);
                    //文字居中
                    labelName.setAlignment(Pos.CENTER);
                    vBox.getChildren().addAll(imageView, labelName);
                    //为文件添加提示信息
                    String information = "文件夹名称：" +fold.getFolderName() + "\n" + "文件夹大小："+fold.getFolderSize(fold)+"B" + "\n" + "文件夹分配盘块号："+ fold.getDiskNum() + "\n文件夹创建时间：" + fold.getCreateTime();
                    Tooltip.install(imageView, new Tooltip(information));
                    arrayListVbox.add(vBox);
                    flowPane.getChildren().add(vBox);
                }else if(folder.getChildren().get(i) instanceof simulateOS.entity.File){
                    simulateOS.entity.File file = (simulateOS.entity.File) folder.getChildren().get(i);
                    String information = "文件名称：" + file.getFileName() +"\n";
                    VBox vBox = new VBox();
                    Label labelName;
                    Image image = null;
                    if(file.isExecutableFile()){
                        labelName = new Label(file.getFileName()+".exe");
                        information = information + "文件类型："+"可执行文件\n";
                        image = new Image(classLoader.getResourceAsStream("image/FileE.png"), 60, 60, true, true);
                    }else {
                        labelName = new Label(file.getFileName()+".txt");
                        information = information + "文件类型："+"文本文件\n";
                        image = new Image(classLoader.getResourceAsStream("image/File.png"), 60, 60, true, true);
                    }
                    if(file.getFlag() == 1){
                        information += "文件状态：可读且可写\n";
                    }else {
                        information += "文件状态：可读\n";
                    }
                    ImageView imageView = new ImageView(image);
                    //限定宽长、像素大小
                    labelName.setStyle("-fx-font: 8 arial;");
                    labelName.setWrapText(true);
                    labelName.setPrefWidth(60);
                    imageView.setPreserveRatio(true);
                    //自动换行
                    labelName.setAlignment(Pos.BASELINE_CENTER);
                    //文字居中
                    labelName.setAlignment(Pos.CENTER);
                    vBox.getChildren().addAll(imageView, labelName);
                    //为文件添加提示信息
                    information = information + "文件大小："+file.getSpace()+"\n"+ "文件分配的起始盘块号：" + file.getPoint().get(0) + "\n" + "文件分配的终盘块号：" + file.getPoint().get(file.getPoint().size() - 1) + "\n" + "文件创建时间："+file.getCreateTime()+"\n";
                    Tooltip.install(imageView, new Tooltip(information));
                    arrayListVbox.add(vBox);
                    flowPane.getChildren().add(vBox);
                }
                arrayListFile.add(folder.getChildren().get(i));
            }
        }

        //事件监听
        fileSetOnAction();
    }

    //事件监听
    private void fileSetOnAction(){
        int length = arrayListFile.size();
        flowPane.setOnMouseClicked(e -> {
            MouseButton eButton = e.getButton();
            if (e.getTarget() instanceof Label) {
                System.out.println("点击了节点");
            } else if (e.getTarget() instanceof Text) {
                System.out.println("点击了文本");
            } else if ((e.getTarget() instanceof FlowPane) && eButton == MouseButton.PRIMARY) {
                //左键点击空白区域，清空选中的图片数据
                System.out.println("点击了空白区域");
                MenuHide();
                cleanImageStyle();
            } else if (e.getTarget() instanceof FlowPane && eButton == MouseButton.SECONDARY) {
                //右键空白区域
                MenuHide();
                cleanImageStyle();
                commonMenuMonitoring(flowPane, e.getScreenX(), e.getScreenY());
            }
        });
        if(!arrayListFile.isEmpty()){
            for(int i = 0;i < length;i++){
                int finalI = i;
                arrayListVbox.get(i).setOnMouseClicked(mouseEvent ->{
                    MouseButton mouseButton = mouseEvent.getButton();
                    double x, y;
                    x = mouseEvent.getScreenX();
                    y = mouseEvent.getScreenY();
                    if(arrayListFile.get(finalI) instanceof Folder){
                        Folder folder = (Folder) arrayListFile.get(finalI);
                        if(mouseButton == MouseButton.PRIMARY){
                            MenuHide();
                            //将点击的文件夹Style设置为浅蓝色
                            cleanImageStyle();
                            arrayListVbox.get(finalI).setStyle("-fx-background-color: #cef4f8 ;");
                            if(mouseEvent.getClickCount() == 2){
                                System.out.println("双击文件夹");
                                openFolder(folder.getPath().getPathName());
                            }
                        }else if(mouseButton == MouseButton.SECONDARY){
                            //将点击的文件夹Style设置为浅蓝色
                            cleanImageStyle();
                            arrayListVbox.get(finalI).setStyle("-fx-background-color: #cef4f8 ;");
                            MenuHide();
                            System.out.println("右键文件夹");
                            folderMenuMonitoring(flowPane,x,y,folder);
                        }
                    }else if(arrayListFile.get(finalI) instanceof simulateOS.entity.File){
                        simulateOS.entity.File file = (simulateOS.entity.File) arrayListFile.get(finalI);
                        if(mouseButton == MouseButton.PRIMARY){
                            //将点击的文件夹Style设置为浅蓝色
                            cleanImageStyle();
                            arrayListVbox.get(finalI).setStyle("-fx-background-color: #cef4f8 ;");
                            MenuHide();
                            if(mouseEvent.getClickCount() == 2){
                                cleanImageStyle();
                                System.out.println("双击，可读模式下打开文件");
                                FAT.getFAT().openFile(file,0);
                            }
                        }else if(mouseButton == MouseButton.SECONDARY){
                            //将点击的文件夹Style设置为浅蓝色
                            cleanImageStyle();
                            arrayListVbox.get(finalI).setStyle("-fx-background-color: #cef4f8 ;");
                            if(file.isExecutableFile()){
                                MenuHide();
                                System.out.println("右键可执行文件");
                                exeMenuMonitoring(flowPane,x,y,file);
                            }else{
                                MenuHide();
                                System.out.println("右键文本文件");
                                txtMenuMonitoring(flowPane,x,y,file);
                            }
                        }
                    }
                });
            }
        }
    }

    private void initMenu(){
        //commonMenu
        menuItems[0] = new MenuItem("粘贴");
        menuItems[15] = new MenuItem("新建文件夹");
        menuItems[16] = new MenuItem("新建文本文件");
        menuItems[17] = new MenuItem("新建可执行文件");
        //folderMenu
        menuItems[1] = new MenuItem("打开");
        menuItems[2] = new MenuItem("删除");
        menuItems[3] = new MenuItem("重命名");
        //txtMenu
        menuItems[4] = new MenuItem("打开");
        menuItems[5] = new MenuItem("编辑");
        menuItems[6] = new MenuItem("复制");
        menuItems[7] = new MenuItem("删除");
        menuItems[8] = new MenuItem("重命名");
        //exeMenu
        menuItems[9] = new MenuItem("打开");
        menuItems[10] = new MenuItem("执行");
        menuItems[11] = new MenuItem("编辑");
        menuItems[12] = new MenuItem("复制");
        menuItems[13] = new MenuItem("删除");
        menuItems[14] = new MenuItem("重命名");

        commonMenu.getItems().addAll(menuItems[0],menuItems[15],menuItems[16],menuItems[17]);
        folderMenu.getItems().addAll(menuItems[1],menuItems[2],menuItems[3]);
        txtMenu.getItems().addAll(menuItems[4],menuItems[5],menuItems[6],menuItems[7],menuItems[8]);
        exeMenu.getItems().addAll(menuItems[9],menuItems[10],menuItems[11],menuItems[12],menuItems[13],menuItems[14]);


    }

    private void MenuHide(){
        commonMenu.hide();
        exeMenu.hide();
        txtMenu.hide();
        folderMenu.hide();
    }

    private void exeMenuMonitoring(FlowPane flowPane, double x, double y, simulateOS.entity.File file){
        exeMenu.show(flowPane,x,y);
        menuItems[9].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                FAT.getFAT().openFile(file,0);
                cleanImageStyle();
            }
        });
        menuItems[10].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                System.out.println("执行可执行文件");
                cleanImageStyle();
                if(!file.isOpen()){
                    /**
                     * 调用进程调度
                     */
                    ProcessManager processManager = (ProcessManager) MainApplication.applicationContext.getBean("processManager");
                    processManager.createProcess(file);
                }else {
                    System.out.println("文件处于打开状态");
                }
            }
        });
        menuItems[11].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                if(file.getFlag() == 1){
                    FAT.getFAT().openFile(file,1);
                }else {
                    System.out.println("文件只可读，无法编辑");
                }
                cleanImageStyle();
            }
        });
        menuItems[12].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                FAT.getFAT().setTemp(file);
                cleanImageStyle();
            }
        });
        menuItems[13].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                FAT.getFAT().showAlert(FAT.getFAT().delete(file));
                DiskUI.getDiskUI().initTheGridPane();
                //DiskUI.getDiskUI().getStage().show();
                treeView.getRoot().getChildren().clear();
                initTreeView();
                openFolder(file.getParent().getPath().getPathName());
            }
        });
        menuItems[14].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                cleanImageStyle();
                System.out.println("重命名");
                if(file.getFlag() == 1){
                    final String[] newName = new String[1];
                    BorderPane borderPane = new BorderPane();
                    TextArea textArea = new TextArea("");
                    textArea.setEditable(true);
                    textArea.setPrefHeight(20);
                    textArea.setPrefWidth(60);
                    Button button = new Button("确定");
                    borderPane.setCenter(textArea);
                    BorderPane t = new BorderPane();
                    t.setCenter(button);
                    borderPane.setBottom(t);
                    Scene scene = new Scene(borderPane);
                    Stage stage = new Stage();
                    stage.setScene(scene);
                    stage.show();
                    button.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent actionEvent) {
                            newName[0] = textArea.getText();
                            stage.close();
                            FAT.getFAT().showAlert(FAT.getFAT().reName(file,newName[0]));
                            openFolder(file.getParent().getPath().getPathName());
                        }
                    });
                }else if(file.getFlag() == 0){
                    System.out.println("文件只可读，无法修改");
                }
            }
        });
    }

    private void txtMenuMonitoring(FlowPane flowPane, double x, double y, simulateOS.entity.File file){
        txtMenu.show(flowPane,x,y);
        menuItems[4].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                FAT.getFAT().openFile(file,0);
                cleanImageStyle();
            }
        });
        menuItems[5].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                if(file.getFlag() == 1){
                    FAT.getFAT().openFile(file,1);
                }else {
                    System.out.println("文件只可读，无法编辑");
                }
                cleanImageStyle();
            }
        });
        menuItems[6].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                FAT.getFAT().setTemp(file);
                cleanImageStyle();
            }
        });
        menuItems[7].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                FAT.getFAT().showAlert(FAT.getFAT().delete(file));
                DiskUI.getDiskUI().initTheGridPane();
                //DiskUI.getDiskUI().getStage().show();
                treeView.getRoot().getChildren().clear();
                initTreeView();
                openFolder(file.getParent().getPath().getPathName());
            }
        });
        menuItems[8].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                cleanImageStyle();
                System.out.println("重命名");
                if(file.getFlag() == 1){
                    final String[] newName = new String[1];
                    BorderPane borderPane = new BorderPane();
                    TextArea textArea = new TextArea("");
                    textArea.setEditable(true);
                    textArea.setPrefHeight(20);
                    textArea.setPrefWidth(60);
                    Button button = new Button("确定");
                    borderPane.setCenter(textArea);
                    BorderPane t = new BorderPane();
                    t.setCenter(button);
                    borderPane.setBottom(t);
                    Scene scene = new Scene(borderPane);
                    Stage stage = new Stage();
                    stage.setScene(scene);
                    stage.show();
                    button.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent actionEvent) {
                            newName[0] = textArea.getText();
                            stage.close();
                            FAT.getFAT().showAlert(FAT.getFAT().reName(file,newName[0]));
                            openFolder(file.getParent().getPath().getPathName());
                        }
                    });
                }else if(file.getFlag() == 0){
                    System.out.println("文件只可读，无法修改");
                }
            }
        });
    }

    private void folderMenuMonitoring(FlowPane flowPane, double x, double y,Folder folder){
        folderMenu.show(flowPane,x,y);
        menuItems[1].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                openFolder(folder.getPath().getPathName());
            }
        });
        menuItems[2].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                FAT.getFAT().showAlert(FAT.getFAT().delete(folder));
                DiskUI.getDiskUI().initTheGridPane();
                //DiskUI.getDiskUI().getStage().show();
                treeView.getRoot().getChildren().clear();
                initTreeView();
                if(folder.hasParent()){
                    openFolder(folder.getParent().getPath().getPathName());
                }
            }
        });
        menuItems[3].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                cleanImageStyle();
                System.out.println("重命名");
                final String[] newName = new String[1];
                BorderPane borderPane = new BorderPane();
                TextArea textArea = new TextArea("");
                textArea.setEditable(true);
                textArea.setPrefHeight(20);
                textArea.setPrefWidth(60);
                Button button = new Button("确定");
                borderPane.setCenter(textArea);
                BorderPane t = new BorderPane();
                t.setCenter(button);
                borderPane.setBottom(t);
                Scene scene = new Scene(borderPane);
                Stage stage = new Stage();
                stage.setScene(scene);
                stage.show();
                button.setOnAction(new EventHandler<ActionEvent>() {
                    @Override
                    public void handle(ActionEvent actionEvent) {
                        newName[0] = textArea.getText();
                        stage.close();
                        FAT.getFAT().showAlert(FAT.getFAT().reName(folder,newName[0]));
                        treeView.getRoot().getChildren().clear();
                        initTreeView();
                        if(folder.hasParent()){
                            openFolder(folder.getParent().getPath().getPathName());
                        }
                    }
                });

            }
        });
    }

    private void commonMenuMonitoring(FlowPane flowPane, double x, double y){
        if(fat.getTemp() == null){
            menuItems[0].setStyle("-fx-text-fill:gray");
        }else {
            menuItems[0].setStyle("-fx-text-fill:black");
        }
        commonMenu.show(flowPane,x,y);
        menuItems[0].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                if(fat.getTemp()!=null){
                    if(getRecentFolder()!=null){
                        fat.paste(getRecentFolder().getPath().getPathName());
                        DiskUI.getDiskUI().initTheGridPane();
                        //DiskUI.getDiskUI().getStage().show();
                        openFolder(getRecentFolder().getPath().getPathName());
                    }
                }
            }
        });
        menuItems[15].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                FAT.getFAT().showAlert(FAT.getFAT().createFolder(recentFolder.getPath().getPathName()));
                DiskUI.getDiskUI().initTheGridPane();
                //DiskUI.getDiskUI().getStage().show();
                treeView.getRoot().getChildren().clear();
                initTreeView();
                openFolder(getRecentFolder().getPath().getPathName());
            }
        });
        menuItems[16].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                FAT.getFAT().showAlert(FAT.getFAT().createFile(recentFolder.getPath().getPathName(),1));
                DiskUI.getDiskUI().initTheGridPane();
                //DiskUI.getDiskUI().getStage().show();
                openFolder(getRecentFolder().getPath().getPathName());
            }
        });
        menuItems[17].setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                FAT.getFAT().showAlert(FAT.getFAT().createExecutableFile(recentFolder.getPath().getPathName(),1));
                DiskUI.getDiskUI().initTheGridPane();
                //DiskUI.getDiskUI().getStage().show();
                openFolder(getRecentFolder().getPath().getPathName());
            }
        });
    }

    private void cleanImageStyle(){
        if (!arrayListVbox.isEmpty()) {
            int j = 0;
            //点击后重置全部图片的Style颜色
            for (j = 0; j < arrayListVbox.size(); j++) {
                arrayListVbox.get(j).setStyle(null);
            }
        }
    }

    private void cleanPreView(){
        flowPane.getChildren().clear();
        arrayListFile.clear();
        arrayListVbox.clear();
    }

    public TextArea getLoad() {
        return load;
    }

    public void setLoad(TextArea load) {
        this.load = load;
    }

    public List<Object> getArrayListFile() {
        return arrayListFile;
    }

    public void setArrayListFile(List<Object> arrayListFile) {
        this.arrayListFile = arrayListFile;
    }

    public List<VBox> getArrayListVbox() {
        return arrayListVbox;
    }

    public void setArrayListVbox(List<VBox> arrayListVbox) {
        this.arrayListVbox = arrayListVbox;
    }

    public Folder getRecentFolder() {
        return recentFolder;
    }

    public void setRecentFolder(Folder recentFolder) {
        this.recentFolder = recentFolder;
    }

    public Folder getOldFolder() {
        return oldFolder;
    }

    public void setOldFolder(Folder oldFolder) {
        this.oldFolder = oldFolder;
    }

    public Stage getStage() {
        return stage;
    }
}
